package cn.com.dhc.danlu.widget.couponview;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.List;

import cn.com.dhc.danlu.R;
import cn.com.dhc.danlu.activity.coupon.DealersCouponObtainAdapter;
import cn.com.dhc.danlu.widget.DLToolbar;
import cn.com.dhc.danlu.widget.base.BasePopupWindow;
import cn.com.dhc.danlu.widget.couponview.filterview.FilterType;
import cn.com.hd.mall.web.webservices.entity.freedom.entity.coupon.ActivityEntity;

/**
 * User: Geek_Soledad(wuhaiyang@danlu.com)
 * Date: 2016-10-01
 * Time: 10:33
 * Description:
 */
public class CouponObtainPopupView extends BasePopupWindow implements View.OnClickListener {
    private View popView;
    private DLToolbar dlToolbar;
    private XRecyclerView mActivityListView;

    public CouponObtainPopupView(Context context, ViewGroup rootView, List<ActivityEntity> entities) {
        super(context);

        initSelf(context, rootView);
        initChildViews();
        setChildViews(context, entities);
        setContentView(popView);
    }

    private void initSelf(Context context, ViewGroup rootView) {
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        setAnimationStyle(R.style.popwin_anim_style);
        setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        popView = LayoutInflater.from(context).inflate(R.layout.popview_good_coupon, rootView, false);
    }

    private void initChildViews() {
        dlToolbar = (DLToolbar) popView.findViewById(R.id.dl_toolbar);
        mActivityListView = (XRecyclerView) popView.findViewById(R.id.xrv_activitylist);
        mActivityListView.setLayoutManager(new LinearLayoutManager(mActivityListView.getContext()));
        mActivityListView.setHasFixedSize(true);
        mActivityListView.setLoadingMoreEnabled(false);
        mActivityListView.setPullRefreshEnabled(false);
    }

    private void setChildViews(Context context, List<ActivityEntity> entities) {
        dlToolbar.setBackVisible(false);
        dlToolbar.setRightClickListenter(this);
        dlToolbar.setTitle("可领优惠券(" + entities.size() + ")");
        popView.findViewById(R.id.v_empty).setOnClickListener(this);

        DealersCouponObtainAdapter adapter = new DealersCouponObtainAdapter(context, FilterType.dealers_coupon);
        mActivityListView.setAdapter(adapter);
        adapter.refreshAllData(entities);
    }

    @Override
    public void onClick(View v) {
        dismiss();
    }
}
